<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

//权限验证
if( Role::init() == false ){
	exit('没有权限');
}

$db = new DB('news');

$orders = isset($_POST['orders']) ? intval($_POST['orders']) : 0;
$title = isset($_POST['title']) ? h($_POST['title']) : '';
$url = isset($_POST['url']) ? h($_POST['url']) : '';
$is_del = 1;
$created = time();
$updated = $created;

//检验必要参数
if( $title == '' || $url == '' ){
	echo '<script>alert("请先填写标题和URL！");window.history.go(-1);</script>';
	exit;
}

//组装news的insert数组
$data=array('title'=>$title,
			'orders'=>$orders,
			'url'=>$url,
			'is_del'=>$is_del,
			'created'=>$created,
			'updated'=>$updated,
			);
$db->table('relative_news')->insert($data)->run();//插入
$insert_id = $db->getId();

//记录动作日志
Log::logs_articles(-2, 14, $insert_id, $title);

$error_title = '添加成功 - 添加推荐文章';
$error_content = '添加成功！';
$error_pre_button = '<a href="/www/admin/news/news_relative.php" style="margin-right:20px;" id="pre_button">〈〈 返回列表</a>';
$error_next_button = '';
require template('admin/news/news_error');
exit;